home *** CD-ROM | disk | FTP | other *** search
/ Monster Media 1996 #15 / Monster Media Number 15 (Monster Media)(July 1996).ISO / prog_c / cuj0696.zip / DWYER.ZIP / PERMUTE.TST / PMTCHISQ.C < prev    next >
C/C++ Source or Header  |  1996-03-26  |  1KB  |  49 lines

  1. /* ============ */
  2. /* pmtchisq.c    */
  3. /* ============ */
  4. #include <stdio.h>
  5. #include <stdlib.h>
  6. #include <string.h>
  7. #include <miscdefs.h>
  8. #include <pmtndefs.h>
  9. #include <assert.h>
  10.  
  11. #define    FULL_SIZE  ((unsigned)RAND_MAX + 1U)
  12. int ScoreCard[FULL_SIZE];
  13. /* ======================================================================= */
  14. /* CalcPermuteChiSq - Calculates Chi-Square Statistic for Permutation Test */
  15. /* ======================================================================= */
  16. void
  17. CalcPermuteChiSq(PRMUT_DATA_STRU  *PermuteData)
  18. {
  19.     long    k;
  20.     double  Coef, SumSq = 0;
  21.  
  22.     memset(ScoreCard, 0, sizeof(int) * PermuteData->NumCategories);
  23.  
  24.     /* ----------------------------------------------------------- */
  25.     /* Generate NumObs (= NumCategories * CellExpect) Permutations */
  26.     /* ----------------------------------------------------------- */
  27.     for (k = 0; k < (long)PermuteData->NumObs; ++k)
  28.     {
  29.     int    NextValue;
  30.  
  31.     NextValue = AnalyzeNextPermutation(PermuteData);
  32.     ++ScoreCard[NextValue];
  33.     }
  34.  
  35.     /* ------------------------------ */
  36.     /* Calculate Chi-Square Statistic */
  37.     /* ------------------------------ */
  38.     for (k = 0; k < PermuteData->NumCategories; ++k)
  39.     {
  40.     SumSq += SQR((double)ScoreCard[k]);
  41.     }
  42.  
  43.     Coef = (double)PermuteData->NumCategories /
  44.         (double)PermuteData->NumObs;
  45.  
  46.     PermuteData->PrmutChiSq =
  47.     Coef * SumSq - (double)PermuteData->NumObs;
  48. }
  49.